package com.yellowpage.client.action;
  
import java.io.IOException;
import java.util.ArrayList;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import com.yellowpage.white.common.Configuration;
import com.yellowpage.white.common.Constants;
import com.yellowpage.white.struts.BaseAction;
import com.yellowpage.white.struts.Module;
import com.yellowpage.white.struts.OperationType;
import com.yellowpage.white.util.Util4Java;

import com.yellowpage.client.data.NspUserPayAccount;
import com.yellowpage.client.service.NspUserPayAccountService;

public class NspUserPayAccountAction extends BaseAction {

    public String RESULT_QUERY = "query";
    public String RESULT_ADD = "add";
	public String RESULT_EDIT = "edit";
	
	private Configuration configuration;
	
	public void setConfiguration(Configuration configuration) {
		this.configuration = configuration;
	}
	
	private List<NspUserPayAccount> nspUserPayAccountList = new ArrayList<NspUserPayAccount>();
	private List<Map> resultList = new ArrayList<Map>();
	
	private NspUserPayAccount nspUserPayAccount;
	private NspUserPayAccountService nspUserPayAccountService;
	
	private String selectedId;	
	private String[] selectedIds;	
	private String message;
	
		private String query_mobileNo;
		private String query_discountSource;
		private String query_dicountDesc;
		private String query_effectTime;
		private String query_effectState;
		private String query_paySource;
		private String query_pay;
		private String query_createTime;
		private String query_payState;
		private String query_submitter;
		private String query_submitTime;
		private String query_updateUser;
		private String query_updateTime;
		private String query_id;
		private String query_desc;
		
	public void prepare() {
		super.prepare();
	
		if (this.selectedId != null && !this.selectedId.equals("")) {
			this.nspUserPayAccount = nspUserPayAccountService.getNspUserPayAccount(Long.parseLong(selectedId));
		}
	}
	
	public String queryByPage() {		
		initPageRender();
		
		Map queryMap = new HashMap();	
			    queryMap.put("mobileNo", query_mobileNo);
	    	    queryMap.put("discountSource", query_discountSource);
	    	    queryMap.put("dicountDesc", query_dicountDesc);
	    	    queryMap.put("effectTime", query_effectTime);
	    	    queryMap.put("effectState", query_effectState);
	    	    queryMap.put("paySource", query_paySource);
	    	    queryMap.put("pay", query_pay);
	    	    queryMap.put("createTime", query_createTime);
	    	    queryMap.put("payState", query_payState);
	    	    queryMap.put("submitter", query_submitter);
	    	    queryMap.put("submitTime", query_submitTime);
	    	    queryMap.put("updateUser", query_updateUser);
	    	    queryMap.put("updateTime", query_updateTime);
	    	    queryMap.put("id", query_id);
	    	    queryMap.put("description", query_desc);
	    	    	
		resultList = nspUserPayAccountService.queryNspUserPayAccountByPage(queryMap, pageRender);
		
		setPageRenderToRequest();

		return RESULT_QUERY;
	}
	
	public String toAdd() {
		return RESULT_ADD;
	}
	
	public String save() {
	    
		nspUserPayAccountService.saveNspUserPayAccount(nspUserPayAccount);		
		
		message = "新增成功!";
		return RESULT_ADD;
	}
	
	public void validateSave() {
	    	    	    if (nspUserPayAccount.getMobileNo().length() == 0) {
			this.addActionError("** 电话号码 不能为空 !");
		}
			    	    	    if (nspUserPayAccount.getDiscountSource().length() == 0) {
			this.addActionError("** 优惠来源 不能为空 !");
		}
			    	    	    if (nspUserPayAccount.getDicountDesc().length() == 0) {
			this.addActionError("** 优惠代码 不能为空 !");
		}
			    	    	    	    	    if (nspUserPayAccount.getEffectState().length() == 0) {
			this.addActionError("** 有效状态 不能为空 !");
		}
			    	    	    if (nspUserPayAccount.getPaySource().length() == 0) {
			this.addActionError("** 支付来源 不能为空 !");
		}
			    	    	    if (nspUserPayAccount.getPay().length() == 0) {
			this.addActionError("** 支付号 不能为空 !");
		}
			    	    	    	    	    if (nspUserPayAccount.getPayState().length() == 0) {
			this.addActionError("** 支付状态 不能为空 !");
		}
			    	    	    if (nspUserPayAccount.getSubmitter().length() == 0) {
			this.addActionError("** 提交者 不能为空 !");
		}
			    	    	    	    	    if (nspUserPayAccount.getUpdateUser().length() == 0) {
			this.addActionError("** 更新者 不能为空 !");
		}
			    	    	    	    	    	    	    if (nspUserPayAccount.getDescription().length() == 0) {
			this.addActionError("** 备注 不能为空 !");
		}
			    	    
		this.setValidatorResult("/client/NspUserPayAccountAdd.jsp");		
	}
	
	public String toEdit() {
	    Long id = new Long(selectedId);
	    
	    nspUserPayAccount = nspUserPayAccountService.getNspUserPayAccount(id);
	
		return RESULT_EDIT;
	}
	
	public String update() {
	
	    nspUserPayAccountService.updateNspUserPayAccount(nspUserPayAccount);	

		message = "修改成功!";
	    
		return RESULT_EDIT;
	}
	
	public void validateUpdate() {
					    if (nspUserPayAccount.getMobileNo().length() == 0) {
			this.addActionError("** 电话号码 不能为空 !");
		}
			    			    if (nspUserPayAccount.getDiscountSource().length() == 0) {
			this.addActionError("** 优惠来源 不能为空 !");
		}
			    			    if (nspUserPayAccount.getDicountDesc().length() == 0) {
			this.addActionError("** 优惠代码 不能为空 !");
		}
			    			    			    if (nspUserPayAccount.getEffectState().length() == 0) {
			this.addActionError("** 有效状态 不能为空 !");
		}
			    			    if (nspUserPayAccount.getPaySource().length() == 0) {
			this.addActionError("** 支付来源 不能为空 !");
		}
			    			    if (nspUserPayAccount.getPay().length() == 0) {
			this.addActionError("** 支付号 不能为空 !");
		}
			    			    			    if (nspUserPayAccount.getPayState().length() == 0) {
			this.addActionError("** 支付状态 不能为空 !");
		}
			    			    if (nspUserPayAccount.getSubmitter().length() == 0) {
			this.addActionError("** 提交者 不能为空 !");
		}
			    			    			    if (nspUserPayAccount.getUpdateUser().length() == 0) {
			this.addActionError("** 更新者 不能为空 !");
		}
			    			    			    			    if (nspUserPayAccount.getDescription().length() == 0) {
			this.addActionError("** 备注 不能为空 !");
		}
			    		this.setValidatorResult("/client/NspUserPayAccountUpdate.jsp");	
	}
	
	public String delete() {	    
	    List ids = new ArrayList();
	    
		for(String id : selectedIds){
			ids.add(Long.valueOf(id));
		}
		
		try {
			this.nspUserPayAccountService.delete(ids);
		} catch (Exception e) {
			System.out.println("异常....");
			this.addActionError("** 可能含有子记录约束冲�?删除失败 !");
		}
		
		
		return queryByPage();
	}	
	
	

	/**
	 * getters and setters
	 * 
	 * @return
	 */
	 public void setNspUserPayAccount(NspUserPayAccount nspUserPayAccount) {
		this.nspUserPayAccount = nspUserPayAccount;
	}
	
	public NspUserPayAccount getNspUserPayAccount() {
		return nspUserPayAccount;
	}
	 
	 
	 public void setNspUserPayAccountService(NspUserPayAccountService nspUserPayAccountService) {
		this.nspUserPayAccountService = nspUserPayAccountService;
	}
	
	public List<NspUserPayAccount> getNspUserPayAccountList() {
		return nspUserPayAccountList;
	}

	public void setNspUserPayAccountList(List<NspUserPayAccount> nspUserPayAccountList) {
		this.nspUserPayAccountList = nspUserPayAccountList;
	}
	
	public String getSelectedId() {
		return selectedId;
	}

	public void setSelectedId(String selectedId) {
		this.selectedId = selectedId;
	}

	public String[] getSelectedIds() {
		return selectedIds;
	}

	public void setSelectedIds(String[] selectedIds) {
		this.selectedIds = selectedIds;
	}

	public String getMessage() {
		return message;
	}

	public void setMessage(String message) {
		this.message = message;
	}
	
	public List<Map> getResultList() {
		return resultList;
	}

	public void setResultList(List<Map> resultList) {
		this.resultList = resultList;
	}
	
	    public String getQuery_mobileNo() {
        return this.query_mobileNo;
    }
    
    public void setQuery_mobileNo(String mobileNo){
        this.query_mobileNo = mobileNo;
    }    

        public String getQuery_discountSource() {
        return this.query_discountSource;
    }
    
    public void setQuery_discountSource(String discountSource){
        this.query_discountSource = discountSource;
    }    

        public String getQuery_dicountDesc() {
        return this.query_dicountDesc;
    }
    
    public void setQuery_dicountDesc(String dicountDesc){
        this.query_dicountDesc = dicountDesc;
    }    

        public String getQuery_effectTime() {
        return this.query_effectTime;
    }
    
    public void setQuery_effectTime(String effectTime){
        this.query_effectTime = effectTime;
    }    

        public String getQuery_effectState() {
        return this.query_effectState;
    }
    
    public void setQuery_effectState(String effectState){
        this.query_effectState = effectState;
    }    

        public String getQuery_paySource() {
        return this.query_paySource;
    }
    
    public void setQuery_paySource(String paySource){
        this.query_paySource = paySource;
    }    

        public String getQuery_pay() {
        return this.query_pay;
    }
    
    public void setQuery_pay(String pay){
        this.query_pay = pay;
    }    

        public String getQuery_createTime() {
        return this.query_createTime;
    }
    
    public void setQuery_createTime(String createTime){
        this.query_createTime = createTime;
    }    

        public String getQuery_payState() {
        return this.query_payState;
    }
    
    public void setQuery_payState(String payState){
        this.query_payState = payState;
    }    

        public String getQuery_submitter() {
        return this.query_submitter;
    }
    
    public void setQuery_submitter(String submitter){
        this.query_submitter = submitter;
    }    

        public String getQuery_submitTime() {
        return this.query_submitTime;
    }
    
    public void setQuery_submitTime(String submitTime){
        this.query_submitTime = submitTime;
    }    

        public String getQuery_updateUser() {
        return this.query_updateUser;
    }
    
    public void setQuery_updateUser(String updateUser){
        this.query_updateUser = updateUser;
    }    

        public String getQuery_updateTime() {
        return this.query_updateTime;
    }
    
    public void setQuery_updateTime(String updateTime){
        this.query_updateTime = updateTime;
    }    

        public String getQuery_id() {
        return this.query_id;
    }
    
    public void setQuery_id(String id){
        this.query_id = id;
    }    

        public String getQuery_desc() {
        return this.query_desc;
    }
    
    public void setQuery_desc(String desc){
        this.query_desc = desc;
    }    

    
	
}
